/* Get total repairs by year*/

use vin cnty_code date_time cap* using "../Smog Check Data/smog_repairs", replace

/* Most of the county codes are 2 digits, and line up with FIPS codes.  There are
single digit county codes 0-4, but these don't seem to match anything, and all the 
supposed repairs are in January 2002.  This is weird--drop them*/

drop if length(cnty_code) == 1

destring cnty_code, gen(county)

replace date_time = regexs(1) if regexm(date_time,"^[AIT](.+)")
gen year = year(date(date_time,"MDYhms"))

gen repair_cost = cap_parts + cap_labor

bysort county year: gen num_repairs = _N

keep if repair_cost >0

gcollapse repair_cost num_repairs, by(county year)

save repairs_county_year, replace